35. Exercise: Sunshine Content Provider and Query

Setup Sunshine's Content Provider and Query

Exercise Code

Exercise: S09.01-Exercise-ContentProviderFoundation

Setup

Setup your content provider by doing the following steps:

SOLUTION:
  • Create WeatherProvider class (with all empty required functions)
  • Write onCreate() function
  • Register the provider in the Android Manifest

URIMatcher

Setup the URIMatcher by completing the following steps:

SOLUTION:
  • Define and add URI’s to the Contract for the authority, paths, and base content uri
  • Build URIMatcher with matches for these two different URI’s: Weather table, Weather with date

Query

Add the query function:

SOLUTION:
  • I'm done!

Test Your Code

Before moving on, test your code.

SOLUTION:
  • Run TestURIMatcher
  • Run TestWeatherProvider